/*
 * Agente.cpp
 *
 *  Created on: 17/05/2012
 *      Author: Shazgath
 */

#include "Agente.h"

std::vector<std::string> parsearRegistro(std::string in) {
	std::vector<std::string> ret;
	std::stringstream ss(in);
	char buffer[BUFFER_SIZE];
	char c = ss.peek();
	while(c != ENDL && !ss.eof()) {
		ss.getline(buffer, BUFFER_SIZE, DELIM);
		std::string sAux(buffer);
		ret.push_back(sAux);
		c = ss.peek();
	}
	return ret;
}


Agente::Agente(std::iostream& input) {
	input >> n_tabla;
	char aux[BUFFER_SIZE];
	input >> aux;
}

Agente::~Agente() {
	// TODO Auto-generated destructor stub
}

/*
int Agente::comenzar(std::istream& input) {
	char buffer[BUFFER_SIZE];
	while(!input.eof()) {
		input.getline(buffer, BUFFER_SIZE);
		//std::cout << buffer;	// luego colocar socket aqui
		std::string s(buffer);
		std::vector<std::string> atribs = parsearRegistro(buffer);
		std::vector<std::string>::iterator it;
		for(it = atribs.begin(); it != atribs.end(); ++it) {
			std::cout << (*it);
		}

	}
	return 0;
}
*/

std::vector<std::string> Agente::comenzar(std::istream& input) {
	char buffer[BUFFER_SIZE];
	std::vector<std::string> atribs;
	while(!input.eof()) {
		input.getline(buffer, BUFFER_SIZE);
		//std::cout << buffer;	// luego colocar socket aqui
		std::string s(buffer);
		atribs = parsearRegistro(buffer);
		std::vector<std::string>::iterator it;

		//for(it = atribs.begin(); it != atribs.end(); ++it) {
		//	return atribs;
		//}
	}
	return atribs;
}

int Agente::enviar(std::vector<std::string> reg) {
	std::string paquete;
	paquete.append(Auxiliar::int_to_dec(n_tabla));
	std::vector<std::string>::iterator it;
	for(it = reg.begin(); it != reg.end(); ++it) {
		paquete.append((*it).c_str());
	}
	//socket.enviar(paquete);
	return 0;
}
